% **************************************************************************************************************
%  A LyX port of:
%  "A Classic Thesis Style" by André Miede
%  LyX port by: Nick Mariette. March, 2009.
%  http://soundsorange.net/resources/classic-thesis-for-lyx/
%
%  Nick Mariette: If you appreciate my LyX port of André Miede's style
%  please visit my homepage and consider making a donation.
%  Also, please consider sending a postcard to André who wrote the original LaTeX (see details below)
% 
%  Note: nm_classicthesis.sty is adapted from classicthesis.sty version 2.5 by André Miede
%  [2008/10/01 v2.5 Typographic Style for a classic-looking thesis]
%
%  All modifications are in the new preamble.sty, the nm_classicthesis.sty, and the .lyx files.
%
% **************************************************************************************************************
%
% classicthesis.sty
%
% Copyright (C) 2008 André Miede http://www.miede.de
%
% If you like the style then I would appreciate a postcard. My address 
% can be found in the file ClassicThesis.pdf. A collection of the 
% postcards I received so far is available online at 
% http://postcards.miede.de
%
% License:
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; see the file COPYING.  If not, write to
% the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
% Boston, MA 02111-1307, USA.
%
% ********************************************************************  
% Important:
%
% This style can also be used without the thesis template.
% It works with both LaTeX and PDFLaTeX now.
%
% * You must not use "u etc. in strings/commands that will be spaced out 
%   (use \"u or real umlauts instead)
% * Chapters must be marked with the \myChapter{Foo} command 
%   (sorry for the inconvenience at this point)
% * For margin notes: \graffito{}
% * There is a problem with the case of math text in part-,
%   chapter-, and section titles (either the case or the spacing breaks). 
%   => this can be fixed by using pdftex 1.40 or later and enabling the
%      option pdfspacing of this package
%
% ********************************************************************  
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{classicthesis}[2008/10/01 v2.5 Typographic Style for a classic-looking thesis]
\RequirePackage{ifthen}
    \newboolean{@tocaligned} % the left column of the toc will be aligned (no indention)
    \newboolean{@eulerchapternumbers} % use AMS Euler for chapter font (otherwise Palatino)
    \newboolean{@drafting} % print version information on pages
    \newboolean{@linedheaders} % chaper headers will have line above and beneath
    \newboolean{@listsseparated} % toggles the vertical space between lof/lot entries of different chapters
    \newboolean{@nochapters} % disable all chapter-specific commands 
    \newboolean{@beramono} % toggle nice monospaced font (w/ bold) + pre-installed 
    \newboolean{@eulermath} % use awesome Euler fonts for math
    \newboolean{@parts} % use part division for the text
    \newboolean{@minionpro} % setup for minion pro font
    \newboolean{@minionprospacing} % use minion pro's textssc for letter spacing
    \newboolean{@pdfspacing} % use pdftex for letterspacing (via microtype)
    \newboolean{@subfig} % setup for preloaded @subfig package
    \newboolean{@a5paper} % use those tiny DIN A5 pages
    
% ********************************************************************
% Options
% ******************************************************************** 
\DeclareOption{tocaligned}{\setboolean{@tocaligned}{true}}
\DeclareOption{eulerchapternumbers}{\setboolean{@eulerchapternumbers}{true}}
\DeclareOption{drafting}{\setboolean{@drafting}{true}}
\DeclareOption{linedheaders}{\setboolean{@linedheaders}{true}}
\DeclareOption{listsseparated}{\setboolean{@listsseparated}{true}}
\DeclareOption{subfigure}{%
    \PackageWarningNoLine{classicthesis}{Package "subfigure" and option "subfigure" are deprecated, used "subfig" instead.}
    \setboolean{@subfig}{true}%
    }
\DeclareOption{subfig}{\setboolean{@subfig}{true}}
\DeclareOption{nochapters}{\setboolean{@nochapters}{true}}
\DeclareOption{beramono}{\setboolean{@beramono}{true}} 
\DeclareOption{eulermath}{\setboolean{@eulermath}{true}} 
\DeclareOption{parts}{\setboolean{@parts}{true}} 
\DeclareOption{a5paper}{\setboolean{@a5paper}{true}}
\DeclareOption{minionpro}{\setboolean{@minionpro}{true}} 
\DeclareOption{minionprospacing}{\setboolean{@minionprospacing}{true}} 
\DeclareOption{pdfspacing}{\setboolean{@pdfspacing}{true}} 
\ProcessOptions\relax

% subfig-related stuff
\@ifpackageloaded{subfig}%
    {\setboolean{@subfig}{true}%
    }{\relax}
\@ifpackageloaded{subfigure}%
    {\setboolean{@subfig}{true}%
     \PackageWarningNoLine{classicthesis}{Package "subfigure" and option "subfigure" are deprecated, %
                                            use "subfig" instead.}
    }{\relax}
\ifthenelse{\boolean{@subfig}}%
    {\PassOptionsToPackage{subfigure}{tocloft}%
    }{\relax}%

% fine-tuning if we use minionprospacing
\ifthenelse{\boolean{@minionprospacing}}%
    {%
        \PackageInfo{classicthesis}{Using option "minionprospacing". %
            This activates "minionpro" in general and turns off %
            the option "pdfspacing".}%
        % is the user trying to use pdfspacing at the same time?    
        \ifthenelse{\boolean{@pdfspacing}}%
            {% both minionprospacing and pdfspacing are active
                \PackageWarningNoLine{classicthesis}{You cannot use "pdfspacing" at the same time %
                    as "minionprospacing"!}%
            }{\relax}%
        \setboolean{@minionpro}{true}%
        \setboolean{@pdfspacing}{false}%
    }{\relax}

% fine-tuning if we do not use chapters
\ifthenelse{\boolean{@nochapters}}%
    {%
        % is the user trying to use parts at the same time?
        \ifthenelse{\boolean{@parts}}%
            {% both parts and nochapters are active
                \PackageWarningNoLine{classicthesis}{You cannot use "parts" at the same time %
                    as "nochapters"!}%
            }{\relax}%
        % turn off some things if we do not use chapters
        \PackageInfo{classicthesis}{Using option "nochapters" (probably for an article). %
                This turns off the options "linedheaders",%
                "listsseparated", "eulerchapternumbers", and "parts". Please be aware of that.}
        \setboolean{@linedheaders}{false}%
        \setboolean{@listsseparated}{false}%
        \setboolean{@eulerchapternumbers}{false}%
        \setboolean{@parts}{false}
    }{\relax}%

% ********************************************************************                
% PDF Stuff
% ********************************************************************
\RequirePackage{ifpdf}
\ifpdf\RequirePackage{hyperref}\fi % for texorpdfstring command below

% ********************************************************************                
% Colors
% ********************************************************************
\RequirePackage[dvipsnames]{xcolor} % [dvipsnames] 
\definecolor{halfgray}{gray}{0.55} % chapter numbers will be semi transparent .5 .55 .6 .0
\definecolor{webgreen}{rgb}{0,.5,0}
\definecolor{webbrown}{rgb}{.6,0,0}
%\definecolor{Maroon}{cmyk}{0, 0.87, 0.68, 0.32}
%\definecolor{RoyalBlue}{cmyk}{1, 0.50, 0, 0}
%\definecolor{Black}{cmyk}{0, 0, 0, 0}

% ********************************************************************
% Font Stuff
% ********************************************************************   
\ifthenelse{\boolean{@minionpro}}%
    {%
        % specialists: MinionPro
        \RequirePackage[opticals,mathlf]{MinionPro} %  opticals, fullfamily, osf
    }{%
        % default: Palatino
        \RequirePackage[osf,sc]{mathpazo} % Palatino with real small caps and old style figures
        \linespread{1.05} % a bit more for Palatino
        % just some font experiments (ignore)
        %\RequirePackage{lmodern}
        %\RequirePackage[urw-garamond]{mathdesign}
        %\RequirePackage[light,condensed,math]{iwona}
        %\renewcommand{\sfdefault}{iwona}
    }

\ifthenelse{\boolean{@beramono}}%
    {\RequirePackage[scaled=0.85]{beramono}}%
    {%
    	\relax%
    	% put your own suitable typewriter font here
    	%\renewcommand{\ttdefault}{\rmdefault}
    } 
\ifthenelse{\boolean{@eulermath}}%
    {\RequirePackage[euler-digits]{eulervm}} % Euler math fonts
    {\relax}
\ifthenelse{\boolean{@eulerchapternumbers}}% font for the chapter numbers
    {\newfont{\chapterNumber}{eurb10 scaled 7000}}%
    {\newfont{\chapterNumber}{pplr9d scaled 7000}}          
    % Euler eurb10 / Palatino OSF pplr9d / Palatino SC pplrc9d
    % Latin Modern cork-lmr10 / Minion MinionPro-Regular-osf-t1
    % (MinionPro-SemiboldCapt-osf-t1 MinionPro-SemiboldDisp-osf-t1)

\RequirePackage{microtype} % character protruding and other micro-typography stuff
% [expansion=false]

% ********************************************************************
% Textblock size
%*******************************************************
\ifthenelse{\boolean{@a5paper}}%
    {% A5
        \ifthenelse{\boolean{@minionpro}}%
        {% Minion gets some extra sizes
        		\PackageInfo{classicthesis}{A5 paper, MinionPro}
            \areaset[5mm]{278pt}{556pt}%
            \setlength{\marginparwidth}{5em}%
            \setlength{\marginparsep}{1.25em}%
        }{% Palatino or other
        		\PackageInfo{classicthesis}{A5 paper, Palatino or other}
            \areaset[5mm]{288pt}{555pt}%
            \setlength{\marginparwidth}{4em}%
            \setlength{\marginparsep}{1.25em}%
        }%
	}{% A4
        \ifthenelse{\boolean{@minionpro}}%
        {% Minion gets some extra sizes
        		\PackageInfo{classicthesis}{A4 paper, MinionPro}
            \areaset[5mm]{288pt}{684pt}% 609 + 33 + 42 head \the\footskip
            \setlength{\marginparwidth}{7.5em}%
            \setlength{\marginparsep}{2em}%
        }{% Palatino or other
        		\PackageInfo{classicthesis}{A4 paper, Palatino or other}
            \areaset[5mm]{312pt}{761pt} % 686 (factor 2.2) + 33 head + 42 head \the\footskip
            \setlength{\marginparwidth}{7em}%
            \setlength{\marginparsep}{2em}%
        }%
	}
% pretty nice:             \areaset[5mm]{391pt}{704pt} % 686 (factor 1.8) 
% nm another golden:             \areaset[5mm]{432pt}{705pt} % 686 (factor 1.62) 
% nm random guess:            \areaset[5mm]{345pt}{690pt} % 686 (factor 2.0)
% nm double square:            \areaset[5mm]{352pt}{704pt} % 686 (factor 2.0)
% nm golden ratio:             \areaset[5mm]{435pt}{705pt} % 686 (factor 1.62)
% nm not bad:             \areaset[5mm]{336pt}{705pt} % 686 (factor 2.1 - suggested) 
% nm original:             \areaset[5mm]{312pt}{761pt} % 686 (factor 2.2) + 33 head + 42 head \the\footskip
% Here are some suggestions for the text widths and heights:
% Palatino 	10pt: 288--312pt | 609--657pt
% Palatino 	11pt: 312--336pt | 657--705pt
% Palatino 	12pt: 
% Minion 	  10pt: 264--288pt | 561--609pt
% Minion 	  11pt: 288--312pt | 609--657pt
% Minion 	  12pt: 

% ********************************************************************
% Own Stuff
% ********************************************************************
% Disable single lines at the start of a paragraph (Schusterjungen)
\clubpenalty = 10000
% Disable single lines at the end of a paragraph (Hurenkinder)
\widowpenalty = 10000 
\displaywidowpenalty = 10000 % formulas

% Graffiti as in GKP's book "Concrete Mathematics"
\DeclareRobustCommand{\graffito}[1]{\marginpar{%
    \slshape\footnotesize%\small%
    %\ifodd\thepage\raggedright\else\raggedleft\fi%
    \parindent=0pt\lineskip=0pt\lineskiplimit=0pt%\baselineskip=10pt
    \tolerance=2000\hyphenpenalty=300\exhyphenpenalty=300%
    \doublehyphendemerits=100000\finalhyphendemerits=\doublehyphendemerits%
    \raggedright\hspace{0pt}#1}}

% Enumeration environment with small caps
\newenvironment{aenumerate}
    {\def\theenumi{\textsc{\alph{enumi}}}%
     \enumerate}
    {\endenumerate}

% ********************************************************************
% Fancy Stuff
% ********************************************************************  
\RequirePackage{booktabs} % for better rules in tables
\RequirePackage{textcase} % for \MakeTextUppercase

\ifthenelse{\boolean{@minionprospacing}}%
    {%
        \PackageInfo{classicthesis}{Using MinionPro's textssc for character spacing.}%
        \DeclareRobustCommand{\spacedallcaps}[1]{\textssc{\MakeTextUppercase{#1}}}%
        \DeclareRobustCommand{\spacedlowsmallcaps}[1]{\textssc{\MakeTextLowercase{#1}}}%
    }{%
        \ifthenelse{\boolean{@pdfspacing}}%
        {%
            \PackageInfo{classicthesis}{Using pdftex/microtype for character spacing.%
                                        Make sure your pdftex is version 1.40 or higher.}%
            \microtypesetup{expansion=false}%
            \DeclareRobustCommand{\spacedallcaps}[1]{\textls[160]{\MakeTextUppercase{#1}}}%
            \DeclareRobustCommand{\spacedlowsmallcaps}[1]{\textls[80]{\scshape\MakeTextLowercase{#1}}}%
        }{%
            \RequirePackage{soul} % for letterspacing 
                \sodef\allcapsspacing{\upshape}{0.15em}{0.65em}{0.6em}%
                \sodef\lowsmallcapsspacing{\scshape}{0.075em}{0.5em}{0.6em}%   
                \DeclareRobustCommand{\spacedallcaps}[1]{\MakeTextUppercase{\allcapsspacing{#1}}}%   
	            \DeclareRobustCommand{\spacedlowsmallcaps}[1]{\MakeTextLowercase{\textsc{\lowsmallcapsspacing{#1}}}}%
        }%
    }

% ********************************************************************                
% headlines
% ********************************************************************  
\RequirePackage[automark]{scrpage2} % provides headers and footers (KOMA Script)
    \clearscrheadings
    \setheadsepline{0pt}
    \ifthenelse{\boolean{@nochapters}}%
        {\relax}%
        {\renewcommand{\chaptermark}[1]{\markboth{\spacedlowsmallcaps{#1}}{\spacedlowsmallcaps{#1}}}}
    \renewcommand{\sectionmark}[1]{\markright{\thesection\enspace\spacedlowsmallcaps{#1}}} 
    \lehead{\mbox{\llap{\small\thepage\kern2em}\headmark\hfil}}
    \rohead{\mbox{\hfil{\headmark}\rlap{\small\kern2em\thepage}}}
    \renewcommand{\headfont}{\small}  
    %\DeclareRobustCommand{\fixBothHeadlines}[1]{} % <--- ToDo
    % hack to get the content headlines right (thanks, Lorenzo!)
		\def\toc@heading{%
	 		\ifthenelse{\boolean{@nochapters}}%
	 		{\section*{\contentsname}}%nochapters
	 		{\chapter*{\contentsname}}%chapters
	 		\@mkboth{\spacedlowsmallcaps{\contentsname}}{\spacedlowsmallcaps{\contentsname}}}

% ********************************************************************
% figures are placed only within section they were declared in
% provides command \FloatBarrier
% ********************************************************************
%\RequirePackage[section,below]{placeins}    
    
% ********************************************************************
% layout of the chapter-, section-, subsection-, subsubsection-,
% paragraph and description-headings
% ********************************************************************             
\RequirePackage{titlesec}
		% parts
		\ifthenelse{\boolean{@parts}}%
		{%
    \titleformat{\part}[display]
        {\normalfont\centering\large}%
        {\thispagestyle{empty}\partname~\MakeTextUppercase{\thepart}}{1em}%
        {\color{Maroon}\spacedallcaps}
    }{\relax}
    % chapters
    \ifthenelse{\boolean{@linedheaders}}%
    {% lines above and below, number right
    \titleformat{\chapter}[display]%             
        {\relax}{\raggedleft{\color{halfgray}\chapterNumber\thechapter} \\ }{0pt}%
        {\titlerule\vspace*{.9\baselineskip}\raggedright\spacedallcaps}[\normalsize\vspace*{.8\baselineskip}\titlerule]%
    }{% something like Bringhurst  
    \titleformat{\chapter}[display]%
        {\relax}{\mbox{}\marginpar{\vspace*{-3\baselineskip}\color{halfgray}\chapterNumber\thechapter}}{0pt}%
        {\raggedright\spacedallcaps}[\normalsize\vspace*{.8\baselineskip}\titlerule]% 
    }
    % sections \FloatBarrier
    \titleformat{\section}
        {\relax}{\textsc{\MakeTextLowercase{\thesection}}}{1em}{\spacedlowsmallcaps}
    % subsections
    \titleformat{\subsection}
        {\relax}{\textsc{\MakeTextLowercase{\thesubsection}}}{1em}{\normalsize\itshape}
    % subsubsections
    \titleformat{\subsubsection}
        {\relax}{\textsc{\MakeTextLowercase{\thesubsubsection}}}{1em}{\normalsize\itshape}        
    % paragraphs
    \titleformat{\paragraph}[runin]
        {\normalfont\normalsize}{\theparagraph}{0pt}{\spacedlowsmallcaps}    
    % descriptionlabels
        \renewcommand{\descriptionlabel}[1]{\hspace*{\labelsep}\spacedlowsmallcaps{#1}}   % spacedlowsmallcaps textit textsc                  
    % spacing
    \ifthenelse{\boolean{@nochapters}}%
        {\relax}%
        {\titlespacing*{\chapter}{0pt}{1\baselineskip}{1.2\baselineskip}}
    \titlespacing*{\section}{0pt}{1.25\baselineskip}{1\baselineskip} 
    \titlespacing*{\subsection}{0pt}{1.25\baselineskip}{1\baselineskip}
    \titlespacing*{\paragraph}{0pt}{1\baselineskip}{1\baselineskip}

% ********************************************************************                
% layout of the TOC, LOF and LOT (LOL-workaround see next section)
% ********************************************************************
\RequirePackage[titles]{tocloft}
    % avoid page numbers being right-aligned in fixed-size box              
    \newlength{\newnumberwidth}
    \settowidth{\newnumberwidth}{99} % yields overfull hbox warnings for pages > 99
    \cftsetpnumwidth{\newnumberwidth}
    % have the bib neatly positioned after the rest
    \newlength{\beforebibskip}  
    \setlength{\beforebibskip}{0em}
    % pagenumbers right after the titles
    % parts
    \ifthenelse{\boolean{@parts}}%
    {%
      \renewcommand{\thepart}{\roman{part}}%
      \renewcommand{\cftpartpresnum}{\scshape}%  \MakeTextLowercase
%      \renewcommand{\cftpartaftersnum}{\cftchapaftersnum}%
%      \renewcommand{\cftpartaftersnumb}{\quad}%
%      \setlength{\cftpartnumwidth}{\cftpartnumwidth}
      \renewcommand{\cftpartfont}{\color{Maroon}\normalfont}%
      \renewcommand{\cftpartpagefont}{\normalfont}%
      \renewcommand{\cftpartleader}{\hspace{1.5em}}% 
      \renewcommand{\cftpartafterpnum}{\cftparfillskip}%        
      \setlength{\cftbeforepartskip}{1em}%
      \setlength{\cftbeforechapskip}{.1em}%
      \setlength{\beforebibskip}{\cftbeforepartskip}%
     }{\relax}
    % chapters
    \ifthenelse{\boolean{@nochapters}}%
        {\relax}%
        {%
        	\renewcommand{\cftchappresnum}{\scshape\MakeTextLowercase}%
            \renewcommand{\cftchapfont}{\normalfont}%
            \renewcommand{\cftchappagefont}{\normalfont}%
            \renewcommand{\cftchapleader}{\hspace{1.5em}}% 
            \renewcommand{\cftchapafterpnum}{\cftparfillskip}% 
            %\setlength{\cftbeforechapskip}{.1em}%           
        }
    % sections
    \ifthenelse{\boolean{@nochapters}}%        
        {%
            \setlength{\cftbeforesecskip}{.1em}%
            \setlength{\beforebibskip}{1em}%
        }%
        {\relax}
    	\renewcommand{\cftsecpresnum}{\scshape\MakeTextLowercase}%
    	\renewcommand{\cftsecfont}{\normalfont}%
        \renewcommand{\cftsecpagefont}{\normalfont}%
        \renewcommand{\cftsecleader}{\hspace{1.5em}} 
        \renewcommand{\cftsecafterpnum}{\cftparfillskip}
        \ifthenelse{\boolean{@tocaligned}}{\renewcommand{\cftsecindent}{0em}}{\relax}
    % subsections
    	\renewcommand{\cftsubsecpresnum}{\scshape\MakeTextLowercase}%
    	\renewcommand{\cftsubsecfont}{\normalfont}%
        \renewcommand{\cftsubsecleader}{\hspace{1.5em}} 
        \renewcommand{\cftsubsecafterpnum}{\cftparfillskip}                
        \ifthenelse{\boolean{@tocaligned}}{\renewcommand{\cftsubsecindent}{0em}}{\relax}
    % figures     
    	\renewcommand{\cftfigpresnum}{\scshape\MakeTextLowercase}% 
    	\renewcommand{\cftfigfont}{\normalfont}%                 
        \renewcommand{\cftfigleader}{\hspace{1.5em}} 
        \renewcommand{\cftfigpresnum}{\figurename~}%Fig.~}
        \renewcommand{\cftfigafterpnum}{\cftparfillskip}
        \newlength{\figurelabelwidth}
        \settowidth{\figurelabelwidth}{\cftfigpresnum~99}
        \addtolength{\figurelabelwidth}{2.5em}
        \cftsetindents{figure}{0em}{\figurelabelwidth}
    % tables
    	\renewcommand{\cfttabpresnum}{\scshape\MakeTextLowercase}%
    	\renewcommand{\cfttabfont}{\normalfont}%
        \renewcommand{\cfttableader}{\hspace{1.5em}} 
        \renewcommand{\cfttabpresnum}{\tablename~}%Tab.~}
        \renewcommand{\cfttabafterpnum}{\cftparfillskip}    
        \newlength{\tablelabelwidth}
        \settowidth{\tablelabelwidth}{\cfttabpresnum~99}
        \addtolength{\tablelabelwidth}{2.5em}
        %\cftsetindents{table}{0em}{\tablelabelwidth}
        \cftsetindents{table}{0em}{\figurelabelwidth}

    % dirty work-around to get the spacing after the toc/lot/lof-titles right    
    \ifthenelse{\boolean{@parts}}%        
    {%
    		\AtBeginDocument{\addtocontents{toc}{\protect\vspace{-\cftbeforepartskip}}}
    }{%
        \ifthenelse{\boolean{@nochapters}}%
    		{\relax}%
    		{\AtBeginDocument{\addtocontents{toc}{\protect\vspace{-\cftbeforechapskip}}}}
    }
                                       
    % another dirty work-around to get the spaced low small caps into the toc ;-(
    \ifthenelse{\boolean{@nochapters}}%
    {\relax}%
    {%
%% w/ optional parameter 
        \newcommand{\myChapter}[2][]{% for chapters
        	\ifthenelse{\equal{#1}{}}{%  
        		%\chapter[\tocEntry{#2}]{#2} % causes soul "reconstruction failed" with plain LaTeX    
            	\ifpdf\chapter[\texorpdfstring{\spacedlowsmallcaps{#2}}{#2}]{#2}%
            	\else\chapter[\spacedlowsmallcaps{#2}]{#2}\fi%
          }{%
          		%\chapter[\tocEntry{#1}]{#2}
          		\ifpdf\chapter[\texorpdfstring{\spacedlowsmallcaps{#1}}{#1}]{#2}%
            	\else\chapter[\spacedlowsmallcaps{#1}]{#2}\fi%
        }}%
%% Old version w/o optional parameter
%        \newcommand{\myChapter}[1]{% for chapters      
%            \ifpdf\chapter[\texorpdfstring{\spacedlowsmallcaps{#1}}{#1}]{#1}%
%            \else\chapter[\spacedlowsmallcaps{#1}]{#1}\fi%
%        }%
    }
    
    % yet another dirty work-around to get the spaced low small caps into the toc ;-(
    \ifthenelse{\boolean{@parts}}%
    {% 
	    	\newcommand{\myPart}[2][]{% for parts     
	    		\ifthenelse{\equal{#1}{}}{%  
		        	\ifpdf%
		        	% ugly hack to remove the part number from the PDF bookmark entry
		        	\pdfstringdefDisableCommands{\let\thepart\@gobbletwo}% 	        
		        	\part[\texorpdfstring{\spacedlowsmallcaps{#2}}{#2}]{#2}% spacedallcaps spacedlowsmallcaps	
		        	\else\part[\spacedlowsmallcaps{#2}]{#2}\fi%
		      }{%
		      		\ifpdf%
		        	% ugly hack to remove the part number from the PDF bookmark entry
		        	\pdfstringdefDisableCommands{\let\thepart\@gobbletwo}% 	        
		        	\part[\texorpdfstring{\spacedlowsmallcaps{#1}}{#1}]{#2}% spacedallcaps spacedlowsmallcaps	
		        	\else\part[\spacedlowsmallcaps{#1}]{#2}\fi%
     		}}%
     }{\relax}
             
    \newcommand{\tocEntry}[1]{% for bib, etc.
    	\ifpdf\texorpdfstring{\spacedlowsmallcaps{#1}}{#1}%
        \else{#1}\fi%
    }

    % remove the vertical space between lof/lot entries of different chapters
    \ifthenelse{\boolean{@listsseparated}}{%
        \AtBeginDocument{%
            \addtocontents{lof}{\protect\vspace{-\cftbeforechapskip}}%
            \addtocontents{lot}{\protect\vspace{-\cftbeforechapskip}}%
        }%
    }{%
        \DeclareRobustCommand*{\deactivateaddvspace}{\let\addvspace\@gobble}% 
        \AtBeginDocument{%      
            \addtocontents{lof}{\deactivateaddvspace}% 
            \addtocontents{lot}{\deactivateaddvspace}%      
            %\addtocontents{lof}{\protect\renewcommand*{\protect\addvspace}[1]{}}% 
            %\addtocontents{lot}{\protect\renewcommand*{\protect\addvspace}[1]{}}% 
        }%
    } 
   
% ********************************************************************
% footnotes setup   
% ********************************************************************
%\RequirePackage{footmisc}  % [bottom] norule para symbol* marginal perpage
    % KOMA-command, footnotemark not superscripted at the bottom
    \deffootnote{0em}{0em}{\thefootnotemark\hspace*{.5em}}      
    %\setfnsymbol{bringhurst}   % use symbols recommended by guru Robert Bringhurst 
    %\setlength{\footnotemargin}{-1em}     
    
% ********************************************************************
% Drafting Stuff
% ********************************************************************
\RequirePackage{scrtime} % time access
\newcommand{\finalVersionString}{}
\ifthenelse{\boolean{@drafting}}{% 
    \RequirePackage[draft]{prelim2e}
        \renewcommand{\PrelimWords}{\relax}
        \renewcommand{\PrelimText}{\footnotesize[\,\today\ at \thistime\,]}
}{\renewcommand{\finalVersionString}{\emph{Final Version} as of \today\ at \thistime.}}   
